﻿using System;
using System.Collections.Generic;
using System.Text;
using Core.Model.Data.Type;
using Core.Parser.ASN1Parser.Nodes;
using Core.Model;
using Core.Model.Data;
using Core.Exceptions;

namespace Core.Parser.ASN1Parser.Builders
{
    internal class ObjectRefBuilder
    {
        internal static ObjectRef Build(ASN1Node node, Group group)
        {
            var ret = new ObjectRef();

            if (node is IntNode)
            {
                ret.ObjectNumber = node.IntValue;
                // Set the group id to the id of this group.
                ret.GroupIdentifier = group.ObjectIdentifier.GroupIdentifier;
            }
            else if (node is SequenceNode)
            {
                var seq = (SequenceNode)node;
                ret.GroupIdentifier = seq.First.StringValue;
                ret.ObjectNumber = seq.Second.IntValue;
            }
            else 
                throw new OpenMhegException("ObjectRef: Argument is not int or sequence");

            return ret;
        }

    }
}
